package com.ssm.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.blog.dao.BlogDAO;
import com.ssm.blog.pojo.Blog;
import com.ssm.blog.pojo.criteria.BlogCriteria;
import com.ssm.blog.service.BlogService;
import com.ssm.blog.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogServiceImpl implements BlogService {
    @Autowired
    private BlogDAO blogDAO;


    @Override
    public PageInfo<Blog> getBlogByCriteria(Integer pageNum, BlogCriteria blog) {
        PageHelper.startPage(pageNum, Constants.BLOG_PAGE_SIZE, "id desc");
        List<Blog> blogList = blogDAO.getBlogByCriteria(blog);
        PageInfo<Blog> page = new PageInfo<>(blogList, 5);
        return page;
    }

    @Override
    public Blog getBlogById(Integer id) {
        return blogDAO.getBlogById(id);
    }
}
